{include file='edit.tpl'}

<div id='categories'></div>

<script>
	createTabs = function() {
		addTab('categories','Рубрики');
	};
	
	$( function() {
		setFirstTabTitle('Новость');
		
		catTree = new jPineCheck($('#categories')[0], {$allCategories});
		catTree.onCheck = function(item) {
			var catIDs = this.getPropertyOfChecked('id');
			$('#categories input[type=hidden]').remove();
			for (var i=0; i<catIDs.length; ++i) {
				$('#categories').append('<input type=hidden name="cat[]" value="'+catIDs[i]+'">');
			}
		}
		var newsCategories = {$newsCategories};
		for (var i=0; i<newsCategories.length; ++i) {
			var catId = newsCategories[i];
			catTree.forEach(function(item) {
				if (item.properties.id == catId) {
					catTree.onClick(item);
					return false;
				}
			} );
		}
		catTree.expandAll();
	} );
</script>